package com.cy.service.factory;

import com.cy.service.RemoteProviderService;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @description:
 *          基于此对象处理RemoteProviderService接口调用时出现的服务中断,超时等问题
 * @author: LiuXingYu
 * @date: 2021/7/31 10:15
 */
@Component
public class RemoteProviderFallbackFactory implements FallbackFactory<RemoteProviderService> {

    /**
     * 此方法会在RemoteProviderService接口服务调用时,出现了异常后执行.
     * @param throwable 用于接收异常
     * @return
     */
    @Override
    public RemoteProviderService create(Throwable throwable) {
        return new RemoteProviderService() {
            @Override
            public String echoMsg(String msg) {
                return "call exception: 服务维护中, 稍等片刻再访问" ;
            }
        };
    }

}
